package com.bite.system.controller.exam;


import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.TableDataInfo;
import com.bite.system.domain.exam.dto.ExamAddDTO;
import com.bite.system.domain.exam.dto.ExamEditDTO;
import com.bite.system.domain.exam.dto.ExamQueryDTO;
import com.bite.system.domain.exam.dto.ExamQuestionDTO;
import com.bite.system.domain.exam.vo.ExamDetailVO;
import com.bite.system.service.exam.IExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService iExamService;


    /**
     * 查看列表
     * 要返回列表相关信息,总条数,code,msg,不妨定义一个新方法TableDataInfo
     * @param examQueryDTO
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO){
        return getTableDataInfo(iExamService.list(examQueryDTO));
    }


    /**
     * 添加竞赛
     * @param examAddDTO
     * @return
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody ExamAddDTO examAddDTO){
        return R.ok(iExamService.add(examAddDTO));
    }


    /**
     * 添加题目
     * @param examQuestionDTO
     * @return
     */
    @PostMapping("/question/add")
    public R<Void> questionAdd(@RequestBody ExamQuestionDTO examQuestionDTO){
        return toR(iExamService.questionAdd(examQuestionDTO));
    }

    /**
     * 删除题目
     * @param
     * @return
     */
    @DeleteMapping("/question/delete")
    public R<Void> questionDelete(Long examId,Long questionId){
        return toR(iExamService.questionDelete(examId,questionId));
    }


    /**
     * 查看编辑信息
     * @param examId
     * @return
     */
    @GetMapping("/detail")
    public R<ExamDetailVO> detail(Long examId){
        return R.ok(iExamService.detail(examId));
    }


    /**
     * 编辑竞赛信息
     * @param examEditDTO
     * @return
     */
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ExamEditDTO examEditDTO){
        return toR(iExamService.edit(examEditDTO));
    }


    /**
     * 竞赛删除
     * @param examId
     * @return
     */
    @DeleteMapping("/delete")
    public R<Void> delete(Long examId){
        return toR(iExamService.delete(examId));
    }


    /**
     * 竞赛发布
     * @param examId
     * @return
     */
    @PutMapping("/publish")
    public R<Void> publish(Long examId){
        return toR(iExamService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    public R<Void> cancelPublish(Long examId){
        return toR(iExamService.cancelPublish(examId));
    }
}
